package pl.vanta.utils.gui.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import pl.vanta.utils.gui.listeners.ExitListener;

public class ExitAction extends AbstractAction
{
	private static final long	serialVersionUID	= 1L;

	private ExitListener		exitListener;

	public ExitAction()
	{
		this(null);
	}

	public ExitAction(ExitListener exitListener)
	{
		this.exitListener = exitListener;
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		if (this.exitListener != null)
		{
			if (!this.exitListener.canExit())
			{
				return;
			}
			
			this.exitListener.onExit();
		}
		
		System.exit(0);
	}
}